package com.imti.mall.sale.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.imti.mall.model.sms.pojo.SmsFlashPromotionProductRelation;
import com.imti.mall.model.sms.vo.SmsCouponProductRelationTo;
import com.imti.mall.model.sms.vo.SmsFlashPromotionProductRelationVo;
import com.imti.mall.sale.dao.SmsFlashPromotionProductRelationDao;
import com.imti.mall.sale.service.SmsFlashPromotionProductRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SmsFlashPromotionProductRelationServiceImpl extends ServiceImpl<SmsFlashPromotionProductRelationDao, SmsFlashPromotionProductRelation> implements SmsFlashPromotionProductRelationService {
    @Autowired
    SmsFlashPromotionProductRelationDao smsFlashPromotionProductRelationDao;
    /**
     * 查询限时购与商品关系表(带分页)
     * @param
     * @return
     */
    @Override
    public List<SmsCouponProductRelationTo> findSmsFlashPromotionProductRelation(SmsCouponProductRelationTo smsCouponProductRelationTo, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return smsFlashPromotionProductRelationDao.findSmsFlashPromotionProductRelation(smsCouponProductRelationTo);
    }

    @Override
    public List<SmsFlashPromotionProductRelationVo> findSmsFlashPromotionProductRelationAndSmsFlashPromotionSession(SmsFlashPromotionProductRelationVo smsFlashPromotionProductRelationVo) {
        return smsFlashPromotionProductRelationDao.findSmsFlashPromotionProductRelationVo(smsFlashPromotionProductRelationVo);
    }

    /**
     * 根据id修改限时购与商品关系表
     * @param smsFlashPromotionProductRelation
     * @return
     */
    @Override
    public Integer updateSmsFlashPromotionProductRelation(SmsFlashPromotionProductRelation smsFlashPromotionProductRelation) {
        return smsFlashPromotionProductRelationDao.updateSmsFlashPromotionProductRelation(smsFlashPromotionProductRelation);
    }
    /**
     * 添加限时购与商品关系表
     * @param list
     * @return
     */
    @Override
    public Integer addSmsFlashPromotionProductRelation(List<SmsFlashPromotionProductRelation> list) {
        Integer res=0;
        for (int i=0;i<list.size();i++){
            smsFlashPromotionProductRelationDao.updateProduct(list.get(i).getProductId().intValue());
            smsFlashPromotionProductRelationDao.insert(list.get(i));
            res=1;
        }
        return  res;

    }
    /**
     * 删除限时购与商品关系表
     * @param smsFlashPromotionProductRelation
     * @return
     */
    @Override
    public Integer deleteSmsFlashPromotionProductRelation(SmsFlashPromotionProductRelation smsFlashPromotionProductRelation) {
        return smsFlashPromotionProductRelationDao.deleteById(smsFlashPromotionProductRelation);
    }
}
